// pages/trade/trade.js

import Http from '../../utils/http.js';

Page({

  /**
   * 页面的初始数据
   */
  data: {
    pageSize: 10,
    pageNumber: 1,
    list: [],
    allLoaded: false,
    queryString: "",
    //输入框相关的操作
    inputVal: ""
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.loadData();
  },
  //滚动到底部触发事件  
  searchScrollLower: function () {
    if (!this.data.allLoaded) {
      this.setData({
        pageNumber: this.data.pageNumber + 1
      });
      this.loadData();
    } else {
      wx.showToast({
        title: '已全部加载',
        icon: 'success',
        duration: 500
      });
    }
  },
  //加载数据
  loadData: function () {
    Http.request({
      url: '/application/findApplicationPage',
      data: {
        queryString: this.data.queryString,
        pageSise: this.data.pageSize,
        pageNumber: this.data.pageNumber
      },
      success: (res) => {
        var data = this.data.list;
        if (res.totalElements > 0) {
          data = data.concat(res["content"]);
        }
        this.setData({
          list: data,
          allLoaded: res["totalPages"] <= this.data.pageNumber
        });
      }
    });
  },
  //完全重新加载数据
  reloadData: function () {
    this.setData({
      list: [],
      allLoaded: false,
      pageSize: 10,
      pageNumber: 1,
    });
    this.loadData();
  },
  applicationDetail: function(e){
    var index = e.currentTarget.dataset.index;
    var list = this.data.list;
    var updateData = list[index];
    wx.navigateTo({
      url: '/pages/finished/detail/detail?applicationId=' + updateData.applicationId
    })
  },
  
  // showInput: function () {
  //   this.setData({
  //     inputShowed: true
  //   });
  // },
  // hideInput: function () {
  //   this.setData({
  //     inputVal: "",
  //     inputShowed: false
  //   });
  // },
  clearInput: function () {
    this.setData({
      inputVal: ""
    });
  },
  clickSearch:function(){
    this.setData({
      queryString: this.data.inputVal
    })
    this.reloadData();
  },
  inputTyping: function (e) {
    this.setData({
      inputVal: e.detail.value
    });
  }
})